﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace mevsukovGames
{
    class ShapeGenerator
    {
        public Shape[] ShapeStack {get; protected set;}
        public Coordinates StartShapeCoordinates { get; protected set; }

        public ShapeGenerator(int x_coordinate, int y_coordinate)
        {
            ShapeStack = new Shape[2];
            StartShapeCoordinates = new Coordinates(x_coordinate, y_coordinate);
            ShapeStack[0] = GenerateRandomShape();
            ShapeStack[1] = GenerateRandomShape();
        }

        public void AddNewShape()
        {
            ShapeStack[0] = ShapeStack[1];
            ShapeStack[1] = GenerateRandomShape();
        }

        public Shape GenerateRandomShape()
        {
            Random rnd = new Random();

            switch (rnd.Next(1, 8))
            {
                case 1:
                {
                    GameBlock block1 = new GameBlock(StartShapeCoordinates.XCoordinate, StartShapeCoordinates.YCoordinate, ConsoleColor.Blue);
                    GameBlock block2 = new GameBlock(StartShapeCoordinates.XCoordinate + 1, StartShapeCoordinates.YCoordinate, ConsoleColor.Blue);
                    GameBlock block3 = new GameBlock(StartShapeCoordinates.XCoordinate, StartShapeCoordinates.YCoordinate - 1, ConsoleColor.Blue);
                    GameBlock block4 = new GameBlock(StartShapeCoordinates.XCoordinate + 1, StartShapeCoordinates.YCoordinate - 1, ConsoleColor.Blue);
                    Square shp = new Square(block1, block2, block3, block4);
                    return shp;
                }
                case 2:
                {
                    GameBlock block1 = new GameBlock(StartShapeCoordinates.XCoordinate, StartShapeCoordinates.YCoordinate, ConsoleColor.Cyan);
                    GameBlock block2 = new GameBlock(StartShapeCoordinates.XCoordinate + 1, StartShapeCoordinates.YCoordinate, ConsoleColor.Cyan);
                    GameBlock block3 = new GameBlock(StartShapeCoordinates.XCoordinate - 1, StartShapeCoordinates.YCoordinate - 1, ConsoleColor.Cyan);
                    GameBlock block4 = new GameBlock(StartShapeCoordinates.XCoordinate, StartShapeCoordinates.YCoordinate - 1, ConsoleColor.Cyan);
                    Shape shp = new Squiggle(block1, block2, block3, block4);
                    return shp;
                }
                case 3:
                {
                    GameBlock block1 = new GameBlock(StartShapeCoordinates.XCoordinate-1, StartShapeCoordinates.YCoordinate, ConsoleColor.DarkGreen);
                    GameBlock block2 = new GameBlock(StartShapeCoordinates.XCoordinate, StartShapeCoordinates.YCoordinate, ConsoleColor.DarkGreen);
                    GameBlock block3 = new GameBlock(StartShapeCoordinates.XCoordinate, StartShapeCoordinates.YCoordinate-1, ConsoleColor.DarkGreen);
                    GameBlock block4 = new GameBlock(StartShapeCoordinates.XCoordinate+1, StartShapeCoordinates.YCoordinate-1, ConsoleColor.DarkGreen);
                    Shape shp = new ReverseSquigle(block1, block2, block3, block4);
                    return shp;
                }
                case 4:
                {
                    GameBlock block1 = new GameBlock(StartShapeCoordinates.XCoordinate - 1, StartShapeCoordinates.YCoordinate+1, ConsoleColor.DarkMagenta);
                    GameBlock block2 = new GameBlock(StartShapeCoordinates.XCoordinate, StartShapeCoordinates.YCoordinate + 1, ConsoleColor.DarkMagenta);
                    GameBlock block3 = new GameBlock(StartShapeCoordinates.XCoordinate, StartShapeCoordinates.YCoordinate, ConsoleColor.DarkMagenta);
                    GameBlock block4 = new GameBlock(StartShapeCoordinates.XCoordinate, StartShapeCoordinates.YCoordinate - 1, ConsoleColor.DarkMagenta);
                    Shape shp = new LBlock(block1, block2, block3, block4);
                    return shp;
                }
                case 5:
                {
                    GameBlock block1 = new GameBlock(StartShapeCoordinates.XCoordinate, StartShapeCoordinates.YCoordinate + 1, ConsoleColor.DarkRed);
                    GameBlock block2 = new GameBlock(StartShapeCoordinates.XCoordinate + 1, StartShapeCoordinates.YCoordinate + 1, ConsoleColor.DarkRed);
                    GameBlock block3 = new GameBlock(StartShapeCoordinates.XCoordinate, StartShapeCoordinates.YCoordinate, ConsoleColor.DarkRed);
                    GameBlock block4 = new GameBlock(StartShapeCoordinates.XCoordinate, StartShapeCoordinates.YCoordinate - 1, ConsoleColor.DarkRed);
                    Shape shp = new RBlock(block1, block2, block3, block4);
                    return shp;
                }
                case 6:
                {
                    GameBlock block1 = new GameBlock(StartShapeCoordinates.XCoordinate-1, StartShapeCoordinates.YCoordinate, ConsoleColor.DarkYellow);
                    GameBlock block2 = new GameBlock(StartShapeCoordinates.XCoordinate, StartShapeCoordinates.YCoordinate, ConsoleColor.DarkYellow);
                    GameBlock block3 = new GameBlock(StartShapeCoordinates.XCoordinate + 1, StartShapeCoordinates.YCoordinate, ConsoleColor.DarkYellow);
                    GameBlock block4 = new GameBlock(StartShapeCoordinates.XCoordinate, StartShapeCoordinates.YCoordinate - 1, ConsoleColor.DarkYellow);
                    Shape shp = new TBlock(block1, block2, block3, block4);
                    return shp;
                }
                case 7:
                {
                    GameBlock block1 = new GameBlock(StartShapeCoordinates.XCoordinate, StartShapeCoordinates.YCoordinate + 1, ConsoleColor.DarkGray);
                    GameBlock block2 = new GameBlock(StartShapeCoordinates.XCoordinate, StartShapeCoordinates.YCoordinate, ConsoleColor.DarkGray);
                    GameBlock block3 = new GameBlock(StartShapeCoordinates.XCoordinate, StartShapeCoordinates.YCoordinate - 1, ConsoleColor.DarkGray);
                    GameBlock block4 = new GameBlock(StartShapeCoordinates.XCoordinate, StartShapeCoordinates.YCoordinate - 2, ConsoleColor.DarkGray);
                    Shape shp = new LinePiece(block1, block2, block3, block4);
                    return shp;
                }
            }
            return null;

        }
    }

}
